package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InventoryWarning;
import com.ruoyi.system.service.IInventoryWarningService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存预警记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/system/warning")
public class InventoryWarningController extends BaseController
{
    private String prefix = "system/warning";

    @Autowired
    private IInventoryWarningService inventoryWarningService;

    @RequiresPermissions("system:warning:view")
    @GetMapping()
    public String warning()
    {
        return prefix + "/warning";
    }

    /**
     * 查询库存预警记录列表
     */
    @RequiresPermissions("system:warning:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InventoryWarning inventoryWarning)
    {
        startPage();
        List<InventoryWarning> list = inventoryWarningService.selectInventoryWarningList(inventoryWarning);
        return getDataTable(list);
    }

    /**
     * 导出库存预警记录列表
     */
    @RequiresPermissions("system:warning:export")
    @Log(title = "库存预警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InventoryWarning inventoryWarning)
    {
        List<InventoryWarning> list = inventoryWarningService.selectInventoryWarningList(inventoryWarning);
        ExcelUtil<InventoryWarning> util = new ExcelUtil<InventoryWarning>(InventoryWarning.class);
        return util.exportExcel(list, "库存预警记录数据");
    }

    /**
     * 新增库存预警记录
     */
    @RequiresPermissions("system:warning:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存预警记录
     */
    @RequiresPermissions("system:warning:add")
    @Log(title = "库存预警记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InventoryWarning inventoryWarning)
    {
        return toAjax(inventoryWarningService.insertInventoryWarning(inventoryWarning));
    }

    /**
     * 修改库存预警记录
     */
    @RequiresPermissions("system:warning:edit")
    @GetMapping("/edit/{warningId}")
    public String edit(@PathVariable("warningId") Long warningId, ModelMap mmap)
    {
        InventoryWarning inventoryWarning = inventoryWarningService.selectInventoryWarningByWarningId(warningId);
        mmap.put("inventoryWarning", inventoryWarning);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存预警记录
     */
    @RequiresPermissions("system:warning:edit")
    @Log(title = "库存预警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InventoryWarning inventoryWarning)
    {
        return toAjax(inventoryWarningService.updateInventoryWarning(inventoryWarning));
    }

    /**
     * 删除库存预警记录
     */
    @RequiresPermissions("system:warning:remove")
    @Log(title = "库存预警记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(inventoryWarningService.deleteInventoryWarningByWarningIds(ids));
    }
}
